package com.hm.ibsm.su;

import java.awt.Image;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;

import com.hm.ibsm.manage.vo.auth.AuthUserVo;
import com.hm.ibsm.window.main.WorkbenchPanel;
import com.hm.ibsm.window.system.user.UserMgtPanel;

/**
 * @author shishun.wang
 * @date 2017年2月18日 下午5:59:24
 * @version 1.0
 * @describe
 */
public class GlobalContent {

	private static GlobalContent globalContent;

	private AuthUserVo currentAuthUser;

	private static Map<String, JPanel> pageContent = new HashMap<String, JPanel>();

	static {
		// 我的工作台
		pageContent.put("4028ac815a56dfd9015a56e4f52f0000", new WorkbenchPanel());
		{// 系统管理
			// 用户管理
			pageContent.put("4028ac815a56dfd9015a56e6d7770002", new UserMgtPanel());
		}
	}

	public static void show(String menuId, JPanel contentPanel) {
		if (!pageContent.containsKey(menuId)) {
			return;
		}
		contentPanel.removeAll();
		contentPanel.add(pageContent.get(menuId));
		contentPanel.repaint();
	}

	public AuthUserVo getCurrentAuthUser() {
		return currentAuthUser;
	}

	public void setCurrentAuthUser(AuthUserVo currentAuthUser) {
		this.currentAuthUser = currentAuthUser;
	}

	private GlobalContent() {

	}

	public static GlobalContent getInstance() {
		if (null == globalContent) {
			synchronized (GlobalContent.class) {
				if (null == globalContent) {
					globalContent = new GlobalContent();
				}
			}
		}
		return globalContent;
	}

	public void loadSystemLogo(JFrame frame) {
		try {
			Image image = ImageIO.read(getClass().getResource("/images/logo.png"));
			frame.setIconImage(image);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
